<template>
  <div>
    {{a}}
  </div>
</template>

<script>
import { ref, onUnmounted } from 'vue';

const SerialPort = window.require('serialport');

export default {
  setup() {
    let timer;
    const getPorts = () => {
      SerialPort.list().then((ports) => {
        ports.forEach((item) => {
          console.log(item);
        });
        // clearInterval(timer);
        console.log(1);
        timer = setTimeout(getPorts, 2000);
        console.log(timer);
      });
    };
    onUnmounted(() => {
      clearTimeout(timer);
    });
    getPorts();
    const a = ref(1);
    return {
      a,
    };
  },
};
</script>

<style>

</style>
